
%identifier='limitedAngle_outerFading_180';
%identifier='limitedAngle_innerFading_180';
identifier='limitedAngle_fixedFading_5_150_180';
imSize=[512,512];
indexStruct=get_indexStruct(identifier,imSize);
num_radial=length(indexStruct);




curvelet=get_curvelet(identifier,imSize,0,0);

for radial=1:num_radial %radial scale
    num_angular=indexStruct(radial);
    for angular=1:num_angular %angular scale
        [curvelet,window_size]=get_curvelet(identifier,imSize,radial,angular);
        point=curvelet{2};
        shift=curvelet{3};
        curvelet=curvelet{1};
        
        subplot(2,2,1);
        imagesc(curvelet);
        subplot(2,2,2);
        window=get_wrapp_window(curvelet,window_size,point,imSize,shift);
        bwindow=get_wrapp_periodization(get_wrapp_window(curvelet,window_size,point,imSize,shift),imSize,shift,point);
        imagesc(bwindow.*curvelet-curvelet.^2);
        subplot(2,2,3);
        imagesc(bwindow.*curvelet);
        subplot(2,2,4);
        imagesc(window);
        pause();
    end
end



%%


%test wrapping with fast algo
%identifier='limitedAngle_outerFading_180';
identifier='limitedAngle_innerFading_180';
%identifier='limitedAngle_fixedFading_5_150_180';
imSize=[512,512];
indexStruct=get_indexStruct(identifier,imSize);
num_radial=length(indexStruct);

% for radial=4:num_radial %radial scale
radial=5;
angular=30;
     num_angular=indexStruct(radial);
%     for angular=1:num_angular %angular scale



[curvelet,window_size]=get_curvelet(identifier,imSize,radial,angular);
img=curvelet{1};
point=curvelet{2};
shift=curvelet{3};

subplot(1,4,1)
imagesc(img)
subplot(1,4,2)
window_size=window_size;%+[-4,2];
img2=get_wrapp_window(img,window_size,point,imSize,shift);
imagesc(img2)
subplot(1,4,3)
img3=get_wrapp_periodization(img2,imSize,shift,point);
size(img);
size(img3);
imagesc(img3);
%imagesc(img3(point(1):point(2),point(3):point(4)));
subplot(1,4,4)
%imagesc(img3(point(1):point(2),point(3):point(4)).*img-img.^2);
imagesc(img3.*img-img.^2);

 %pause();
 %    end
% end
%img3=zeros(imSize);
%img3(point(1):point(2),point(3):point(4))=img;
%img3=get_wrapp_window(img3,window_size);
%imagesc(img3);


%%


%identifier='limitedAngle_innerFading_180';
identifier='limitedAngle_fixedFading_10_130_150';
%identifier='limitedAngle_outerFading_180';
imSize=[2^10,2^10];
indexStruct=get_indexStruct(identifier,imSize);
num_radial=length(indexStruct);




curvelet=get_curvelet(identifier,imSize,0,0);
fail=false;
for radial=1:num_radial %radial scale
    num_angular=indexStruct(radial);
    for angular=1:num_angular %angular scale
        [curvelet,window_size]=get_curvelet(identifier,imSize,radial,angular);
        point=curvelet{2};
        shift=curvelet{3};
        curvelet=curvelet{1};
        
        subplot(2,2,1);
        imagesc(curvelet);
        subplot(2,2,2);
        window=get_wrapp_window(curvelet,window_size,point,imSize,shift);
        bwindow=get_wrapp_periodization(get_wrapp_window(curvelet,window_size,point,imSize,shift),imSize,shift,point);
        imagesc(bwindow.*curvelet-curvelet.^2);
        subplot(2,2,3);
        imagesc(bwindow.*curvelet);
        subplot(2,2,4);
        imagesc(window);
        if(max(bwindow(:).*curvelet(:)-curvelet(:).^2)>0)
            fail=true;
            fprintf('fail!');
            pause();
        else
            fprintf('.');
        end
    end
    fprintf('\n');
end
if(fail)
    fprintf('Test failed!\n');
else
    fprintf('Test succesfull!\n');
end

